package cz.anime.ppro.logic;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cz.anime.ppro.model.Content;
import cz.anime.ppro.repositories.ContentRepository;

@Component
public class ContentComponentImpl implements ContentComponent {

	@Autowired
	private ContentRepository contentRepository;
	
	@Override
	public List<Content> getContent() {
		return contentRepository.findAll();
	}
	
	@Override
	public Content getContent(int id) {
		return contentRepository.findContentById(id);
	}
	
	@Override
	public List<Content> getContentByFragment(int fragmentId) {
		return contentRepository.findContentByFragmentId(fragmentId);
	}
	
	@Override
	public void delete(Content content) {
		contentRepository.delete(content);		
	}
	
	@Override
	public void save(Content content) {
		contentRepository.saveAndFlush(content);
	}
}
